package io.renren.modules.sell.controller;

import io.renren.common.annotation.SysLog;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.modules.sell.entity.ProductCategory;
import io.renren.modules.sell.service.ProducetCategoryService;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @ClassName SellerCategoryController
 * @Author mengjiafeng
 * @Date 2020/4/11 13:31
 **/
@RestController
@RequestMapping("/seller/category")
public class SellerCategoryController extends AbstractController {
    @Autowired
    ProducetCategoryService producetCategoryService;
    @GetMapping("/list")
    public R getCategoryList(){
        List<ProductCategory> categoryListlist = producetCategoryService.listBysellerId(getUserId());
        return R.ok().put("list",categoryListlist);
    }
    @GetMapping("/info/{categoryId}")
    public R getCategory(@PathVariable("categoryId") Integer categoryId){
        ProductCategory productCategory = producetCategoryService.getById(categoryId);
        return R.ok().put("productCategory",productCategory);

    }
    @SysLog("保存类目")
    @PostMapping("/save")
    @Transactional
    public R save(@RequestBody ProductCategory productCategory){

        productCategory.setSellerId(getUserId());
        productCategory.setCreateTime(new Date());
        productCategory.setUpdateTime(new Date());
        producetCategoryService.save(productCategory);

        return R.ok();
    }

    @SysLog("更新类目")
    @PostMapping("/update")
    @Transactional
    public R update(@RequestBody ProductCategory productCategory){

        productCategory.setUpdateTime(new Date());
        producetCategoryService.updateById(productCategory);

        return R.ok();
    }

    //批量删除订单
    @PostMapping("/delete")
    public R listByUserId(@RequestBody Integer[] categoryIds){
        producetCategoryService.deleteBatch(categoryIds);
        return R.ok();
    }
}
